<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Let's check that our main namespace "Kesillo" is properley installed. 
 * 
 * This file use the manifesto to know which namespaces are to be
 * used, by default only Kesillo is defined. All the namespaces are to be placed
 * in LIBPATH/<namespace> and follow the PSR-0 guidelines. Each namespace must 
 * have a <namespace>App.php in APPSPATH, if it is not found it will load
 * APPSPASTH/DefaultApp.php. Any app or namespace can extend other namespaces
 * found in LIBPATH.
 *
 * 
 * Let's load up our AutoLoaders. This is an array or AutoLoaders to load. This
 * allows to use any namespace with their own autoloaders.
 * 
 * @todo Make it actually load different autoloaders.
 */
$autoLoaders = Array (
    'Kesillo' => LIBPATH.'Kesillo/Core/AutoLoader'.EXT
);

error_reporting(E_ALL & ~E_STRICT);

/**
 * Load them up. Each autoloader should register itself. For the moment we want
 * the namespaces and classes to be loaded automatically. Therefore, we create 
 * the autoloaders so that they dont need be instatiated.
 */
foreach ($autoLoaders as $autoLoader) {
    if (is_file($autoLoader))
        require $autoLoader;
    else
        throw new Exception ("Autoloader: $autoLoader was not found.");
}

/**
 *This whole section below needs a lot of work.
 *  
 *Let's get the manifestor and load up the default up. And Let's go to our default app. 
 */
require_once SYSPATH.'Manifesto'.EXT;

AppInit($app[$DefaultApp]);

// TODO: When instatiating the class pass all the app's info to the class constructor
/*
 * Ok, we now we must pass the $app[$DefaultApp] data so that the app actually works.
 * We need this so that we can find files related to the app itself from the controller
 */
function AppInit(Array $appInfo = NULL)
{
    foreach ($appInfo as $key => $value) {
            define($key, $value);
        }
        
    require $appInfo['AppKernel'];
    
    $k = new $appInfo['AppName']();
    //$k->$appInfo['DefaultAction']();
    $k->main();
}